package com.hmdp.service.impl;

import com.hmdp.config.RabbitMQConfig;
import com.hmdp.service.IRabbitMQService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class RabbitMQServiceImpl implements IRabbitMQService {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    public void sendVoucherMessage(String message) {
        try {
            rabbitTemplate.convertAndSend(
                    RabbitMQConfig.VOUCHER_EXCHANGE,
                    RabbitMQConfig.VOUCHER_ROUTING_KEY,
                    message
            );
            log.info("发送消息到RabbitMQ成功: {}", message);
        } catch (Exception e) {
            log.error("发送消息到RabbitMQ失败: {}", e.getMessage());
        }
    }
}